import { defineStore } from 'pinia'
import { computed, ref } from 'vue'

const useDialogStore = defineStore('dialog', () => {
  /**
   * 弹窗层级
   */
  const zIndex = ref(2000)

  /**
   * 添加弹窗层级
   */
  const addZIndex = () => {
    ++zIndex.value
  }

  /**
   * 减少弹窗层级
   */
  const minusZIndex = () => {
    if (zIndex.value > 2000) {
      --zIndex.value
    }
  }

  /**
   * 获取弹窗层级
   */
  const getZIndex = computed(() => {
    return zIndex.value
  })

  return {
    getZIndex,
    addZIndex,
    minusZIndex,
  }
})

export default useDialogStore
